package com.zsck.zsgy.ui.auth
import androidx.lifecycle.MutableLiveData
import com.zsck.zsgy.api.ApiService
import com.zsck.zsgy.base.BaseRepository
import com.zsck.zsgy.http.RetrofitManager
import com.zsck.zsgy.http.exception.ApiException
import com.zsck.zsgy.ui.auth.bean.AuthBean
import com.zsck.zsgy.ui.guide.bean.KeyListBean
import com.zsck.zsgy.ui.guide.bean.VersionListBean
import kotlinx.coroutines.CoroutineScope

/**
 *登录的数据仓
 */
class AuthRepo(coroutineScope: CoroutineScope, errorLiveData: MutableLiveData<ApiException>) :
    BaseRepository(coroutineScope, errorLiveData) {

    /**
     * 登录
     */
    fun auth(verificationCode:String,phoneNumber:String,registrationId:String,loginLiveData:MutableLiveData<AuthBean>){
        launch(block = {
            RetrofitManager.getApiService(ApiService::class.java)
                .getLogin(verificationCode,phoneNumber,registrationId)
                .data
        },success = {
            loginLiveData.postValue(it)
        })

    }


    /**
     * 获取服务器版本
     */

    fun postGetVersion(type: HashMap<String, String>?, splashLiveData:MutableLiveData<List<VersionListBean>>){
        launch(block = {
            type?.let {
                RetrofitManager.getApiService(ApiService::class.java)
                    .postGetVersion(it).data
            }
        },success = {
            splashLiveData.postValue(it)
        })
    }

    /**
     * 获取值集
     */
    fun getKeyList(pkPath:String,splashKeyModel:MutableLiveData<KeyListBean>){
        launch(block = {
            RetrofitManager.getApiService(ApiService::class.java)
                .getKeyList(pkPath)
                .data
        },success = {
            splashKeyModel.postValue(it)
        })
    }

}